home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / dagMenuProc.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  29.8 KB  |  1,111 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //  Alias|Wavefront Script File
  18. //  MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //  Creation Date:  Dec 3, 1996
  21. //
  22. //
  23. //  Description:
  24. //      This script describes the contents of the context sensitive menus.
  25. //
  26. //  Input Arguments:
  27. //      None.
  28. //
  29. //  Return Value:
  30. //      None.
  31. //
  32.  
  33. proc optionalDagMenuProc( string $parent, string $item )
  34. {
  35.     // Look at the shape child of this object
  36.     //
  37.     string $object[] = `listRelatives -path -s $item`;
  38.     string $shape = "";
  39.     int $gotVisible = 0;
  40.  
  41.     if( size($object) < 1 ) return;
  42.  
  43.     for( $i=0; $i<size($object); $i+=1) {
  44.         if( (0 == getAttr($object[$i] + ".io")) &&
  45.             getAttr($object[$i] + ".v") ) {
  46.             $shape = $object[$i];
  47.             $gotVisible = 1;
  48.             break;
  49.         }
  50.     }
  51.  
  52.     if( !$gotVisible ) {
  53.         for( $i=0; $i<size($object); $i+=1) {
  54.             if( 0 == getAttr($object[$i] + ".io")) {
  55.                 $shape = $object[$i];
  56.                 break;
  57.             }
  58.         }
  59.     }
  60.  
  61.     if( "" != $shape ) {
  62.         string $nt = `nodeType $shape`;
  63.         switch( $nt ) {
  64.           case "subdiv":
  65.             subdOptionalDagMenuProc( $parent, $item );
  66.             menuItem -d true; 
  67.             break;
  68.  
  69.           default:
  70.             break;
  71.         }
  72.     }
  73. }
  74.  
  75. proc int objectIsTrimmed(string $item)
  76. // Return true if this is a trimmed surface
  77. {
  78.     string $command = ("getAttr -size " + $item + ".trimFace");
  79.     int $trimCount = eval($command);
  80.  
  81.     return ($trimCount != 0);
  82. }
  83.  
  84. global proc string[] objectSelectMasks(string $item)
  85. // Returns the component selection masks that apply to this object
  86. {
  87.     string $maskList[];
  88.     string $shape = $item;
  89.     int $i;
  90.  
  91.     // Look at the shape child of this object
  92.     //
  93.     string $object[] = `listRelatives -path -s $item`;
  94.     int $gotVisible = 0;
  95.  
  96.     for ($i = 0; $i < size($object); ++$i) {
  97.         if( (0 == getAttr($object[$i] + ".io")) &&
  98.             getAttr($object[$i] + ".v") ) {
  99.             $shape = $object[$i];
  100.             $gotVisible = 1;
  101.             break;
  102.         }
  103.     }
  104.  
  105.     if( !$gotVisible ) {
  106.         for ($i = 0; $i < size($object); ++$i)
  107.         {
  108.             if (getAttr($object[$i] + ".io") == 0)
  109.             {
  110.                 $shape = $object[$i];
  111.                 break;
  112.             }
  113.         }
  114.     }
  115.  
  116.     string $nt = `nodeType $shape`;
  117.  
  118.     switch ($nt) {
  119.         case "lattice":
  120.             $maskList[0] = "latticePoint";
  121.             break;    
  122.         case "nurbsCurve":
  123.             $maskList[0] = "curveParameterPoint";
  124.             $maskList[1] = "controlVertex";
  125.             $maskList[2] = "editPoint";
  126.             $maskList[3] = "hull";
  127.             break;
  128.         case "nurbsSurface":
  129.             $maskList[0] = "isoparm";
  130.             $maskList[1] = "controlVertex";
  131.             $maskList[2] = "surfaceParameterPoint";
  132.             $maskList[3] = "hull";
  133.             $maskList[4] = "surfaceFace";
  134.             if (objectIsTrimmed($shape)) {
  135.                 $maskList[5] = "surfaceEdge";
  136.             }
  137.             break;
  138.         case "mesh":
  139.             $maskList[0] = "edge";
  140.             $maskList[1] = "vertex";
  141.             $maskList[2] = "facet";
  142.             $maskList[3] = "puv";
  143.             $maskList[4] = "pvf";
  144.             break;
  145.         case "joint":
  146.             $maskList[0] = "joint";        // special case
  147.             break;
  148.         case "ikHandle":
  149.             $maskList[0] = "ikHandle";    // special case
  150.             break;
  151.         case "particle":
  152.             $maskList[0] = "particle";    // only one choice
  153.             break;
  154.         case "spring":
  155.             $maskList[0] = "springComponent";    // only one choice
  156.             break;
  157.         case "subdiv":
  158.              $maskList[0] = "subdivMeshPoint";    
  159.              $maskList[1] = "subdivMeshEdge";    
  160.              $maskList[2] = "subdivMeshFace";    
  161.              $maskList[3] = "subdivMeshUV";    
  162.             break;
  163.     }
  164.     return $maskList;
  165. }
  166.  
  167. global proc createSelectMenuItems(string $parent, string $item)
  168. // Create a menu that shows the dag parenting for this object
  169. {
  170.     string $maskList[] = `objectSelectMasks($item)`;
  171.     string $radialPosition[];
  172.     string $uiName;
  173.  
  174.     int $i;
  175.     int $isNurbObject     = false;
  176.     int $isPolyObject     = false;
  177.     int $isLatticeObject  = false;
  178.     int $isJointObject    = false;
  179.     int $isIkHandleObject = false;
  180.     int $isParticleObject = false;
  181.     int $isSpringObject   = false;
  182.     int $isSubdivObject   = false;
  183.     int $hasComponents      = false;
  184.  
  185.     //    Work around for bug #143031. A small problem with new Java/MEL.
  186.     //    Comparing an element in an empty array will increase the array
  187.     //    to accomodate that element.
  188.     //
  189.     //    To avoid this, first test the size of the array before comparing
  190.     //    elements that may not exist.
  191.     //
  192.     if (1 <= size($maskList)) {
  193.         $isLatticeObject = ($maskList[0] == "latticePoint");
  194.         $isJointObject = ($maskList[0] == "joint");
  195.         $isIkHandleObject = ($maskList[0] == "ikHandle");
  196.         $isParticleObject = ($maskList[0] == "particle");
  197.         $isSpringObject = ($maskList[0] == "springComponent");
  198.         $isSubdivObject = ($maskList[0] == "subdivMeshPoint");
  199.     }
  200.     if (2 <= size($maskList)) {
  201.         $isNurbObject = ($maskList[1] == "controlVertex");
  202.         $isPolyObject = ($maskList[1] == "vertex");
  203.     }
  204.  
  205.     $hasComponents = $isLatticeObject || 
  206.                      $isParticleObject ||
  207.                      $isSubdivObject ||
  208.                      $isSpringObject ||
  209.                      $isNurbObject ||
  210.                      $isPolyObject;
  211.  
  212.     // NOTE: 
  213.     //            If the object has selectable components, then the
  214.     //        radial position "NE" will be used for the menuItem:  
  215.     //        "Revert back to object mode."
  216.     //
  217.     setParent -menu $parent;
  218.     $radialPosition[0] = "N";
  219.     $radialPosition[1] = "W";
  220.     $radialPosition[2] = "S";
  221.     $radialPosition[3] = "E";
  222.     $radialPosition[4] = "SW";
  223.     $radialPosition[5] = "SE";
  224.     $radialPosition[6] = "NW";
  225.     $radialPosition[7] = "NE";
  226.  
  227.     if ($isNurbObject) {
  228.         for ($i = 0; $i < size($maskList); $i++) {
  229.             switch ($maskList[$i]) {
  230.                 case "surfaceParameterPoint":
  231.                     $uiName = "Surface Point";
  232.                     break;
  233.                 case "curveParameterPoint":
  234.                     $uiName = "Curve Point";
  235.                     break;
  236.                 case "surfaceEdge":
  237.                     $uiName = "Trim Edge";
  238.                     break;
  239.                 case "surfaceFace":
  240.                     $uiName = "Surface Patch";
  241.                     break;
  242.                 default:
  243.                     $uiName = `interToUI $maskList[$i]`;
  244.             }
  245.             menuItem -l $uiName
  246.                 -ecr false
  247.                 -c ( "doMenuNURBComponentSelection(\"" +
  248.                     $item + "\", \"" +  $maskList[$i] + "\")")
  249.                 -rp $radialPosition[$i];
  250.         }
  251.     } else if ($isPolyObject) {
  252.         
  253.         for ($i = 0; $i < size($maskList); $i++) {
  254.  
  255.             switch ($maskList[$i]) {
  256.               case "puv":
  257.                 $uiName = "UV";
  258.                 break;
  259.               case "facet":
  260.                 $uiName = "Face";
  261.                 break;
  262.               case "pvf":
  263.                 $uiName = "Vertex Faces";
  264.                 break;
  265.               default:
  266.                 $uiName = `interToUI $maskList[$i]`;
  267.                 break;
  268.             }
  269.             menuItem -l $uiName
  270.                 -ecr false
  271.                 -c ( "doMenuComponentSelection(\"" +
  272.                     $item + "\", \"" +  $maskList[$i] + "\")")
  273.                 -rp $radialPosition[$i];
  274.         }
  275.     } else if ($isLatticeObject) {
  276.                 for ($i = 0; $i < size($maskList); $i++) {
  277.             $uiName = `interToUI $maskList[$i]`;
  278.             menuItem -l $uiName
  279.                 -ecr false
  280.                 -c ( "doMenuLatticeComponentSelection(\"" +
  281.                     $item + "\", \"" +  $maskList[$i] + "\")")
  282.                 -rp $radialPosition[$i];
  283.         }
  284.     } else if ($isJointObject) {
  285.         menuItem -l "Set Preferred Angle"
  286.             -echoCommand true
  287.             -c (`performSetPrefAngle 2` + " " + $item)
  288.             -rp "W"
  289.             setPrefAngleItem;
  290.  
  291.         menuItem -l "Assume Preferred Angle"
  292.             -echoCommand true
  293.             -c (`performAssumePrefAngle 2` + " " + $item)
  294.             -rp "E"
  295.             assumePrefAngleItem;
  296.  
  297.         // Check if the current context is the skinPaint context 
  298.         // and the the joint is connected to a skinCluster
  299.         //
  300.         string  $currContext = `currentCtx`;
  301.         string  $currTool    = `contextInfo -c $currContext`;
  302.         if ( $currTool == "artAttrSkin" ) {
  303.             string $whichTool = `artAttrCtx -q -whichTool $currContext`;
  304.             if ( $whichTool == "skinWeights" )  {
  305.                 string $connL[] = `listConnections ($item+".worldMatrix")`;
  306.                 string $conn;
  307.                 for($conn in $connL)
  308.                     if (`nodeType $conn` == "skinCluster")
  309.                     {    
  310.                         // select the surface (not the joint) and set
  311.                         // the joint as the current influence
  312.                         //
  313.                         string $currSel[] = `ls -sl`;
  314.                         string $currSelString;
  315.                         if (size($currSel) > 0) {
  316.                             string $currObj;
  317.                             $currSelString = "select -r ";
  318.                             for ($currObj in $currSel) {
  319.                                 $currSelString += ($currObj+" ");
  320.                             }
  321.                         }
  322.                         menuItem -l "Paint Weights"
  323.                             -echoCommand true
  324.                             -c ($currSelString+"; setSmoothSkinInfluence " + $item)
  325.                             -rp "N"
  326.                             paintWeightItem;
  327.                         break;
  328.                     }
  329.             }
  330.         }
  331.     } else if ($isIkHandleObject) {
  332.         menuItem -l "Set Preferred Angle"
  333.             -annotation "Set Preferred: Select ikHandles or joints"
  334.             -echoCommand true
  335.             -c (`performSetPrefAngle 2` + " " + $item)
  336.             -rp "W"
  337.             setPrefAngleItem;
  338.  
  339.         menuItem -l "Assume Preferred Angle"
  340.             -annotation "Assume Preferred: Select ikHandles or joints"
  341.             -echoCommand true
  342.             -c (`performAssumePrefAngle 2` + " " + $item)
  343.             -rp "E"
  344.             assumePrefAngleItem;
  345.  
  346.         menuItem -l "Enable ikHandle"
  347.             -annotation "Enable IK Handles: Select ikHandles"
  348.             -echoCommand true
  349.             -c ("ikHandle -e -eh " + $item)
  350.             -rp "N"
  351.             enableIKHandlesItem;
  352.  
  353.         menuItem -l "Disable ikHandle"
  354.             -annotation "Disable IK Handles: Select ikHandles"
  355.             -echoCommand true
  356.             -c ("ikHandle -e -dh " + $item)
  357.             -rp "S"
  358.             disableIKHandlesItem;
  359.  
  360.         menuItem -l "Enable Snap"
  361.             -annotation "Enable IK Handle Snapping: Select ikHandles"
  362.             -echoCommand true
  363.             -c ("ikHandle -e -see " + $item + ";" +
  364.                 "ikHandle -e -shf on " + $item)
  365.             -rp "NE"
  366.             enableIKHandlesSnapItem;
  367.  
  368.         menuItem -l "Disable Snap"
  369.             -annotation "Disable IK Handle Snapping: Select ikHandles"
  370.             -echoCommand true
  371.             -c ("ikHandle -e -shf off " + $item)
  372.             -rp "SW"
  373.             disableIKHandlesSnapItem;
  374.  
  375.     } else if ($isParticleObject) {
  376.         for ($i = 0; $i < size($maskList); $i++) {
  377.             switch ($maskList[$i]) {
  378.                 case "particle":
  379.                     $uiName = "Particle";
  380.                     break;
  381.                 default:
  382.                     $uiName = `interToUI $maskList[$i]`;
  383.             }
  384.             menuItem -l $uiName
  385.                 -ecr false
  386.                 -c ( "doMenuParticleComponentSelection(\"" +
  387.                     $item + "\", \"" +  $maskList[$i] + "\")")
  388.                 -rp $radialPosition[$i];
  389.         }
  390.     } else if ($isSpringObject) {
  391.         for ($i = 0; $i < size($maskList); $i++) {
  392.             switch ($maskList[$i]) {
  393.                 case "springComponent":
  394.                     $uiName = "Spring";
  395.                     break;
  396.                 default:
  397.                     $uiName = `interToUI $maskList[$i]`;
  398.             }
  399.             menuItem -l $uiName
  400.                 -ecr false
  401.                 -c ( "doMenuSpringComponentSelection(\"" +
  402.                     $item + "\", \"" +  $maskList[$i] + "\")")
  403.                 -rp $radialPosition[$i];
  404.         }
  405.     } else if ($isSubdivObject) {
  406.         subdDagMenuProc( 0, $item, $maskList );
  407.     } else {
  408.         for ($i = 0; $i < size($maskList); $i++) {
  409.             $uiName = `interToUI $maskList[$i]`;
  410.             menuItem -l $uiName
  411.                 -ecr false
  412.                 -c ( "doMenuComponentSelection(\"" +
  413.                     $item + "\", \"" +  $maskList[$i] + "\")")
  414.                 -rp $radialPosition[$i];
  415.         }
  416.     } 
  417.  
  418.     // If components are present, provide the ability to 
  419.     // get back to object mode...
  420.     //
  421.     if ($hasComponents) {
  422.         menuItem -l "Object Mode"
  423.                 -ecr false
  424.                 -c ( "hilite -unHilite " + $item + "; string $selection[] = `ls -sl`;"
  425.                     + "changeSelectMode -object; select -r $selection;" )
  426.                 -rp "NE";
  427.     }
  428.  
  429. //    for ($i = 0; $i < size($maskList); $i++) {
  430. //       $itemName = "SELM" + string($i);
  431. //            setParent -menu $parent;
  432. //            menuItem
  433. //                -c ("doMenuComponentSelection(\"" + 
  434. //                    $item + "\", \"" +  $maskList[$i] + "\")")
  435. //                -l $maskList[$i]
  436. //                -rp $radialPosition[$i]
  437. //                $itemName;
  438. //    }
  439.     setParent -menu $parent;
  440. }
  441.  
  442. global proc doMenuNURBComponentSelection(string $item, string $mask)
  443. //
  444. // Change the selection/display state to allow selection of NURB components
  445. //
  446. {
  447.     string $selectCmd;
  448.  
  449.     if (`selectMode -q -object`) {
  450.         hilite $item;
  451.         selectType -ocm -alc false;
  452.         $selectCmd = "selectType -ocm -" + $mask + " true;";
  453.     } else {
  454.         selectType -ocm -alc false;
  455.         $selectCmd = "selectType -" + $mask + " true;";
  456.         if (`selectMode -q -preset`) {
  457.             $selectCmd = $selectCmd +"selectPriority -allComponents 1;";
  458.             $selectCmd = $selectCmd +"selectPriority -isoparm 2;";
  459.             $selectCmd = $selectCmd +"selectPriority -" + $mask + " 3;";
  460.             switch ($mask) {
  461.                 case "editPoint":
  462.                     $selectCmd = $selectCmd + 
  463.                         "toggle -state true -" + $mask + " " + $item +";"; 
  464.                     $selectCmd = $selectCmd + 
  465.                         "toggle -state false -hull " + $item + ";";
  466.                     $selectCmd = $selectCmd + 
  467.                         "toggle -state false -controlVertex " + $item + ";";
  468.                     break;
  469.                 case "controlVertex":
  470.                     $selectCmd = $selectCmd + 
  471.                         "toggle -state true -" + $mask + " " + $item +";"; 
  472.                     $selectCmd = $selectCmd + 
  473.                         "toggle -state false -hull " + $item + ";";
  474.                     $selectCmd = $selectCmd + 
  475.                         "toggle -state false -editPoint " + $item + ";";
  476.                     break;
  477.                 case "hull":
  478.                     $selectCmd = $selectCmd + 
  479.                         "toggle -state true -" + $mask + " " + $item + ";"; 
  480.                     $selectCmd = $selectCmd + 
  481.                         "toggle -state false -controlVertex " + $item + ";";
  482.                     $selectCmd = $selectCmd + 
  483.                         "toggle -state false -editPoint " + $item + ";";
  484.                     break;
  485.                 default:
  486.                     $selectCmd = $selectCmd + 
  487.                         "toggle -state false -hull " + $item + ";";
  488.                     $selectCmd = $selectCmd + 
  489.                         "toggle -state false -controlVertex " + $item + ";";
  490.                     $selectCmd = $selectCmd + 
  491.                         "toggle -state false -editPoint " + $item + ";";
  492.                     break;
  493.             }
  494.         } else {
  495.             $selectCmd = $selectCmd + "hilite " + $item + ";";
  496.         }
  497.     }
  498.  
  499.     eval $selectCmd;
  500. }
  501.  
  502. global proc doMenuLatticeComponentSelection(string $item, string $mask)
  503. //
  504. // Changes the selection/display state on this object to allow
  505. // selection of the Lattice control points
  506. {
  507.     string $selectCmd;
  508.  
  509.     if (`selectMode -q -object`) {
  510.         hilite $item;
  511.         selectType -ocm -alc false;
  512.         $selectCmd = "selectType -ocm -" + $mask + " true;";
  513.     } else {
  514.         selectType -ocm -alc false;
  515.         $selectCmd = "selectType -" + $mask + " true;";
  516.         if (!`selectMode -q -preset`) {
  517.             $selectCmd = $selectCmd + "hilite " + $item + ";";
  518.         } else {
  519.             $selectCmd = $selectCmd + "toggle -" + $mask + ";"; 
  520.         }
  521.     }
  522.     eval $selectCmd;
  523. }
  524.  
  525.  
  526. global proc doMenuParticleComponentSelection(string $item, string $mask)
  527. //
  528. // Change the selection/display state to allow selection of particle
  529. // components
  530. //
  531. {
  532.     string $selectCmd;
  533.  
  534.     if (`selectMode -q -object`) {
  535.         hilite $item;
  536.         selectType -ocm -alc false;
  537.         $selectCmd = "selectType -ocm -" + $mask + " true;";
  538.     } else {
  539.         selectType -ocm -alc false;
  540.         $selectCmd = "selectType -" + $mask + " true;";
  541.         if (`selectMode -q -preset`) {
  542.             $selectCmd = $selectCmd +"selectPriority -allComponents 1;";
  543.             $selectCmd = $selectCmd +"selectPriority -particle 2;";
  544.             $selectCmd = $selectCmd +"selectPriority -" + $mask + " 3;";
  545.             switch ($mask) {
  546.                 case "particle":
  547.                     $selectCmd = $selectCmd + 
  548.                         "toggle -state true -" + $mask + " " + $item +";"; 
  549.                     break;
  550.                 default:
  551.                     $selectCmd = $selectCmd + 
  552.                         "toggle -state false -particle " + $item + ";";
  553.                     break;
  554.             }
  555.         } else {
  556.             $selectCmd = $selectCmd + "hilite " + $item + ";";
  557.         }
  558.     }
  559.  
  560.     eval $selectCmd;
  561. }
  562.  
  563.  
  564. global proc doMenuSpringComponentSelection(string $item, string $mask)
  565. //
  566. // Change the selection/display state to allow selection of spring
  567. // components
  568. //
  569. {
  570.     string $selectCmd;
  571.  
  572.     if (`selectMode -q -object`) {
  573.         hilite $item;
  574.         selectType -ocm -alc false;
  575.         $selectCmd = "selectType -ocm -" + $mask + " true;";
  576.     } else {
  577.         selectType -ocm -alc false;
  578.         $selectCmd = "selectType -" + $mask + " true;";
  579.         if (`selectMode -q -preset`) {
  580.             $selectCmd = $selectCmd +"selectPriority -allComponents 1;";
  581.             $selectCmd = $selectCmd +"selectPriority -springComponent 2;";
  582.             $selectCmd = $selectCmd +"selectPriority -" + $mask + " 3;";
  583.             switch ($mask) {
  584.                 case "springComponent":
  585.                     $selectCmd = $selectCmd + 
  586.                         "toggle -state true -" + $mask + " " + $item +";"; 
  587.                     break;
  588.                 default:
  589.                     $selectCmd = $selectCmd + 
  590.                         "toggle -state false -springComponent " + $item + ";";
  591.                     break;
  592.             }
  593.         } else {
  594.             $selectCmd = $selectCmd + "hilite " + $item + ";";
  595.         }
  596.     }
  597.  
  598.     eval $selectCmd;
  599. }
  600.  
  601.  
  602. global proc doMenuComponentSelection(string $item, string $mask)
  603. //
  604. // Changes the selection/display state on this object to allow
  605. // selection of the specified selection mask type.
  606. {
  607.     string $selectCmd;
  608.  
  609.     if (`selectMode -q -object`) {
  610.         hilite $item;
  611.         selectType -ocm -alc false;
  612.         $selectCmd = "selectType -ocm -" + $mask + " true;";
  613.     } else {
  614.         selectType -ocm -alc false;
  615.         $selectCmd = "selectType -" + $mask + " true;";
  616.         if (!`selectMode -q -preset`) {
  617.             $selectCmd = $selectCmd + "hilite " + $item + ";";
  618.         }
  619.     }
  620.     eval $selectCmd;
  621. }
  622.  
  623. global proc undoMenuComponentSelection(string $item, string $mask)
  624. {
  625.     string $selectCmd;
  626.  
  627.     if (`selectMode -q -object`) {
  628.         $selectCmd = "selectType -ocm -" + $mask + " false;";
  629.     } else {
  630.         $selectCmd = "selectType -" + $mask + " false;";
  631.     }
  632.  
  633.     eval $selectCmd;
  634. }
  635.  
  636. global proc toggleBoundingBoxDisplay ( string $parent )
  637. //
  638. // For each shape under the selected parent object, toggle the
  639. // state of bounding box display mode.
  640. //
  641. {
  642.     string $shapes[] = `listRelatives -shapes $parent`;
  643.     string $shape;
  644.  
  645.     for ( $shape in $shapes ) {
  646.         int $overrideOn = `getAttr ( $shape + ".overrideEnabled")`;
  647.         int $lodMode =    `getAttr ( $shape + ".overrideLevelOfDetail")`;
  648.         int $enabled =     $overrideOn && $lodMode == 1;
  649.  
  650.         if ( $enabled ) {
  651.             // Don't reset the overrideEnabled attribute. It
  652.             // is used for more than just bounding box display
  653.             // and turning if off will mess things up of you
  654.             // have temporarily enabled bounding box display 
  655.             // of an object in a layer.
  656.             setAttr ( $shape + ".overrideLevelOfDetail" ) 0;
  657.         } else {
  658.             setAttr ( $shape + ".overrideEnabled") 1;
  659.             setAttr ( $shape + ".overrideLevelOfDetail") 1;
  660.         }
  661.  
  662.     }
  663. }
  664.  
  665. global proc createActionsMenuItems(string $parent, string $item)
  666. //
  667. // Creates a menu with common operations to perform on an object
  668. //
  669. {    
  670.     popupMenu -e -dai $parent;
  671.     setParent -menu $parent;
  672.  
  673.     menuItem -l "Template" -c ("toggle -template -state on " + $item);
  674.     menuItem -l "Untemplate" -c ("toggle -template -state off " + $item);
  675.     menuItem -l "Unparent" -c ("parent -w " + $item);
  676.     menuItem -l "Bounding Box" -c ("toggleBoundingBoxDisplay " + $item);
  677. }
  678.  
  679.  
  680. global proc showSG(string $item)
  681. //
  682. //    Display the Attribute Editor and show the tab for the
  683. //    shading group that is on the object $item.
  684. //
  685. //  If would have been nicer to be able to use the
  686. //    showShadingGroupAttributeEditor command, but it only 
  687. //  acts on the    selected object.
  688. //
  689. {
  690.     string $allNodes[] = (`listHistory -f true $item` );
  691.     string $node = "";
  692.     for ($node in $allNodes) {
  693.         if(`nodeType $node` == "shadingEngine") {
  694.             showEditor $node;
  695.             break;
  696.         }
  697.     }
  698. }
  699.  
  700. global proc showBakeSets(string $item, string $type)
  701. //
  702. //    Display the Attribute Editor and show the tab for the
  703. //    first bake set of the specified $type that the object $item is in.
  704. //  If there is no this $type of bake set in the scene, creates the
  705. //  initial bake set of this type and show it in the attribute editor.
  706. //
  707. //  If would have been nicer to be able to use the
  708. //    showBakeSetAttributeEditor command, but it only 
  709. //  acts on the    selected object.
  710. //
  711. {
  712.     string $possibleBakeSets[] = (`listHistory -f true $item` );
  713.     string $node = "";
  714.     int $bakeSetExists = false;
  715.     for ($node in $possibleBakeSets) {
  716.         if(`nodeType $node` == $type)
  717.         {
  718.             showEditor $node;
  719.             $bakeSetExists = true;
  720.             break;
  721.         }
  722.     }
  723.  
  724.     // If no bake set exists for the $item, then create the
  725.     // initial bake set of that $type and assign it to the $item.
  726.     //
  727.     if (!$bakeSetExists)
  728.     {
  729.         string $initialBakeSet = "";
  730.         if($type == "vertexBakeSet") 
  731.         {
  732.             $initialBakeSet = "initialVertexBakeSet";
  733.         }
  734.         else if($type == "textureBakeSet") 
  735.         {
  736.             $initialBakeSet = "initialTextureBakeSet";
  737.         }
  738.         else
  739.         {
  740.             error   -showLineNumber true
  741.                 ("Bake set type "+$type + " does not exist.");
  742.             return;
  743.         }
  744.  
  745.         // Create it if it does not exist yet.
  746.         //
  747.         if  ( size(`ls $initialBakeSet`) < 1)
  748.         {
  749.             createBakeSet($initialBakeSet, $type);
  750.         } 
  751.     
  752.         // Assign the initial bake set to the item.
  753.         //
  754.         assignBakeSet($initialBakeSet, $item);
  755.  
  756.         // Show the initial bake set.
  757.         //
  758.         showBakeSetAE($initialBakeSet);
  759.     }
  760. }
  761.  
  762. global proc createShaderMenuItems(string $parent, string $item)
  763. //
  764. //    Create the Shader menus for the RMB popup menu.
  765. //
  766. {
  767.     popupMenu -e -deleteAllItems $parent;
  768.     setParent -menu $parent;
  769.  
  770.     menuItem -l "Material Attributes..." -c ("showSG " + $item);
  771.     menuItem -d true;
  772.  
  773.     buildShaderMenus($item);
  774. }
  775.  
  776. // Description:  This procedure is called to refresh the baking 
  777. //  attribute menu items.
  778. //
  779. global proc refreshBakingAttributeMenu (string $parent, string $item)
  780. {
  781.     setParent -menu $parent;
  782.  
  783.     int $suitable = bakeSetTypeSuitableForItem("textureBakeSet", $item);
  784.     menuItem -edit -enable $suitable textureBakingAttributeItem;
  785.     $suitable = bakeSetTypeSuitableForItem("vertexBakeSet", $item);
  786.     menuItem -edit -enable $suitable vertexBakingAttributeItem;
  787. }
  788.  
  789. // Description:  This procedure is called to create the 
  790. //  baking attribute menu.
  791. //
  792. proc createBakingAttributeMenu(string $parent, string $item)
  793. {
  794.     setParent -menu $parent;
  795.  
  796.     menuItem -l "Edit Attributes..." 
  797.         -subMenu true
  798.         -tearOff true
  799.         -postMenuCommand ("refreshBakingAttributeMenu \""
  800.                             +$parent+"|editAttributeItem\" \""
  801.                             +$item+"\"")
  802.         editAttributeItem; 
  803.  
  804.  
  805.         menuItem -l "texture" 
  806.             -c ("showBakeSets \""+$item+"\" \"textureBakeSet\"") 
  807.             textureBakingAttributeItem;
  808.         menuItem -l "vertex" 
  809.             -c ("showBakeSets \""+$item+"\" \"vertexBakeSet\"") 
  810.             vertexBakingAttributeItem;
  811.  
  812.     setParent -menu ..;
  813. }
  814.  
  815. // Description:  This procedure is called to create the baking
  816. //  menu items.
  817. //
  818. global proc createBakingMenuItems(string $parent, string $item)
  819. //
  820. //    Create the Baking menus for the RMB popup menu.
  821. //
  822. {
  823.     popupMenu -e -deleteAllItems $parent;
  824.     setParent -menu $parent;
  825.  
  826.     createBakingAttributeMenu($parent, $item);
  827.     menuItem -d true;
  828.  
  829.     buildBakingMenus($item);
  830. }
  831.  
  832.  
  833. global proc createHistoryMenuItems(string $parent, string $item)
  834. //
  835. // Creates a menu on the toolbar that shows a list of
  836. // all operations that took place to create/modify
  837. // the currently selected object.  Note that the list
  838. // is not being filtered yet to get rid of things that
  839. // users won't really care about, nor are the operations
  840. // being listed as operations - their DG node names are
  841. // simply being stuck into the menu.  This should
  842. // change.
  843. //
  844. // Also note that the chain of operations limit is being
  845. // hardcoded to 20 here, for the sake of speed.
  846. //
  847. {
  848.     //
  849.     // Delete all menu entries currently in the popup
  850.     //
  851.     popupMenu -e -dai $parent;
  852.     setParent -menu $parent;
  853.  
  854.     historyPopupFill( $item, false, 1 );
  855. }
  856.  
  857. global proc createFutureMenuItems(string $parent, string $item)
  858. //
  859. // Creates a menu on the toolbar that shows a list of
  860. // all operations that took place to create/modify
  861. // the currently selected object.  Note that the list
  862. // is not being filtered yet to get rid of things that
  863. // users won't really care about, nor are the operations
  864. // being listed as operations - their DG node names are
  865. // simply being stuck into the menu.  This should
  866. // change.
  867. //
  868. // Also note that the chain of operations limit is being
  869. // hardcoded to 20 here, for the sake of speed.
  870. //
  871. {
  872.     //
  873.     // Delete all menu entries currently in the popup
  874.     //
  875.     popupMenu -e -dai $parent;
  876.     setParent -menu $parent;
  877.  
  878.     historyPopupFill( $item, true, 1 );
  879. }
  880.  
  881. global proc string objectHandlesUvSets(string $item)
  882. {
  883.     string $maskList[];
  884.     string $shape = $item;
  885.     int $i;
  886.  
  887.     // Look at the shape child of this object
  888.     //
  889.     string $object[] = `listRelatives -path -s $item`;
  890.     int $gotVisible = 0;
  891.  
  892.     for ($i = 0; $i < size($object); ++$i) {
  893.         if( (0 == getAttr($object[$i] + ".io")) &&
  894.             getAttr($object[$i] + ".v") ) {
  895.             $shape = $object[$i];
  896.             $gotVisible = 1;
  897.             break;
  898.         }
  899.     }
  900.  
  901.     if( !$gotVisible ) {
  902.         for ($i = 0; $i < size($object); ++$i)
  903.         {
  904.             if (getAttr($object[$i] + ".io") == 0)
  905.             {
  906.                 $shape = $object[$i];
  907.                 break;
  908.             }
  909.         }
  910.     }
  911.     string $nt = `nodeType $shape`;
  912.  
  913.     if ($nt == "mesh")    
  914.         return $shape;
  915.     return "";
  916. }
  917.  
  918. global proc createUVsetMenuItems(string $parent, string $item,
  919.                                  string $shape)
  920. {
  921.     popupMenu -e -dai $parent;
  922.     setParent -menu $parent;
  923.  
  924.     string $cmd = "polyUVSet -currentUVSet -uvSet ";
  925.     string $curSet[] = `polyUVSet -q -currentUVSet $shape`;
  926.     string $names[] = `polyUVSet -q -auv $shape`;
  927.  
  928.     string $allProjects[] = `polyUVSet -pr -q $shape`;
  929.     string $setClearCmd = "";
  930.     if (size($allProjects))
  931.     {
  932.         $setClearCmd = "select -d ";        
  933.         for ($p=0; $p<size($allProjects); $p++)
  934.             $setClearCmd += (" " + $allProjects[$p]);
  935.         $setClearCmd += ";";
  936.     }
  937.  
  938.     int $numNames = size($names);
  939.  
  940.     // Add in a menu to do uv-linking
  941.     if ($numNames > 0)
  942.     {    
  943.         string $ann = `getRunTimeCommandAnnotation "UVCentricUVLinkingEditor"`;
  944.         string $cmd = "UVCentricUVLinkingEditor; " + "select -r " + $item;
  945.         menuItem -l "UV Linking..."
  946.             -c $cmd
  947.             -annotation $ann;
  948.         menuItem -divider true;
  949.     }
  950.  
  951.     for ($i=0; $i<$numNames; $i++)
  952.     {
  953.         string $uvEditname = ("\"" + $names[$i] + "\"");
  954.         string $uvname = $names[$i];
  955.         string $setCurCmd = $cmd + $uvEditname + " " + $shape + ";";
  956.  
  957.         // Find any projections associated with the uvset
  958.         string $projs[];
  959.         $projs = `polyUVSet -pr -uvs $uvname -q $shape`;
  960.         string $projCmd;
  961.  
  962.         // Add a divider between items
  963.         if ($i > 0)
  964.             menuItem -divider true;
  965.  
  966.         if ($uvname == $curSet[0])
  967.         {
  968.             menuItem -l ($uvname) -c $setClearCmd -checkBox true;
  969.             for ($j=0; $j<size($projs); $j++)
  970.             {
  971.                 $projCmd = ($setClearCmd + "select -add "+ $projs[$j] + ";setToolTo ShowManips;"); 
  972.                 menuItem -l $projs[$j] -c $projCmd;
  973.                 if ($j >= 5)
  974.                     break;
  975.             }
  976.         }
  977.         else
  978.         {
  979.             menuItem -l ($uvname) -c ($setClearCmd + $setCurCmd) -checkBox false;
  980.             for ($j=0; $j<size($projs); $j++)
  981.             {
  982.                 $projCmd = ($setCurCmd + $setClearCmd + "select -add "+ $projs[$j] + ";setToolTo ShowManips;"); 
  983.                 menuItem -l $projs[$j] -c $projCmd;
  984.                 if ($j >= 5)
  985.                     break;
  986.             }
  987.         }
  988.     }
  989. }
  990.  
  991. // This has been called because a menu press happened on a DAG object
  992. // So find the Object submenu and add the DAG specific items to it.
  993. //
  994. global proc dagMenuProc(string $parent, string $object)
  995. {
  996.     string $mode = "All";
  997.  
  998.     if (`optionVar -exists currentMenuBarTab`) {
  999.         $mode = `optionVar -q currentMenuBarTab`;
  1000.     } else {
  1001.         optionVar -sv currentMenuBarTab $mode;
  1002.     }
  1003.  
  1004.     if (`popupMenu -e -exists $parent`) {
  1005.         setParent -m $parent;
  1006.  
  1007.         // label the object
  1008.         string $shortName = `substitute ".*|" $object ""`;
  1009.         menuItem -l ($shortName + "...") -c ("showEditor "+$object);
  1010.         menuItem -divider true;
  1011.         menuItem -divider true;
  1012.  
  1013.         // Create the list of selection masks
  1014.         createSelectMenuItems($parent, $object);
  1015.  
  1016.         menuItem -d true;
  1017.  
  1018.         menuItem -l "Select" -c ("select -r " + $object);
  1019.  
  1020.         menuItem -d true;
  1021.  
  1022.         optionalDagMenuProc( $parent, $object );
  1023.  
  1024.         // create the history menu
  1025.         //
  1026.         string $menu = `menuItem -subMenu true -aob true -l "Inputs"`;
  1027.         menu -e 
  1028.             -pmc ( "createHistoryMenuItems \""+$menu+"\" "+$object ) $menu;
  1029.         setParent -m $parent;
  1030.  
  1031.         $menu = `menuItem -subMenu true -aob true -l "Outputs"`;
  1032.         menu -e -pmc ( "createFutureMenuItems \""+$menu+"\" "+$object ) $menu;
  1033.         setParent -m $parent;
  1034.  
  1035.         string $paintAttr = `artBuildPaintMenu $object`;
  1036.         if ($paintAttr != "")
  1037.         {
  1038.             string $parent       = `menuItem -subMenu true -aob true -l "Paint"`;
  1039.  
  1040.             // Create the menu.
  1041.             artAttrCreateMenuItems( $parent, $paintAttr );
  1042.         }
  1043.         setParent -m $parent;
  1044.  
  1045.         $menu = `menuItem -subMenu true -l "Actions"`;
  1046.         menu -e -pmc ( "createActionsMenuItems \""+$menu+"\" "+$object ) $menu;
  1047.         setParent -m $parent;
  1048.  
  1049.         // If the object can handle uv sets then add the uvset menu
  1050.         //
  1051.         string $shape = objectHandlesUvSets( $object );
  1052.         if ($shape != "")
  1053.         {
  1054.             $menu = `menuItem -subMenu true -l "UV Sets"`;
  1055.             menu -e 
  1056.                 -pmc ( "createUVsetMenuItems \""+$menu+"\" " +$object + " "+
  1057.                       $shape )
  1058.                 $menu;
  1059.             setParent -m $parent;
  1060.         }
  1061.  
  1062.         // Shader menu to be able to quickly assign existing shaders
  1063.         // to the object under the pointer.
  1064.         //
  1065.         menuItem -d true;
  1066.  
  1067.          $menu = `menuItem -subMenu true -l "Materials"`;
  1068.          menu -e
  1069.             -pmc ( "createShaderMenuItems \""+$menu+"\" "+$object )
  1070.             $menu;
  1071.          setParent -m $parent;
  1072.  
  1073.         int $mentalIsLoaded = 0;
  1074.         string $renderer;
  1075.         for ($renderer in `renderer -query -namesOfAvailableRenderers`) {
  1076.             if( $renderer == "mentalRay" ) {
  1077.                 $mentalIsLoaded = 1;
  1078.                 break;
  1079.             }
  1080.         }
  1081.  
  1082.         if ($mentalIsLoaded) {
  1083.              $menu = `menuItem -subMenu true -l "Baking"`;
  1084.              menu -e
  1085.                 -pmc ( "createBakingMenuItems \""+$menu+"\" "+$object )
  1086.                 $menu;
  1087.              setParent -m $parent;
  1088.         }
  1089.  
  1090.         {
  1091. //             $menu = `menuItem -subMenu true -l "Paint"`;
  1092. //             menu -e
  1093. //                 -pmc ( "createPaintingMenuItems \""+$menu+"\" "+$object )
  1094. //                $menu;
  1095. //             setParent -m $parent;
  1096.         }
  1097.  
  1098.         if ($mode == "Dynamics") {
  1099.             menuItem -d true;
  1100.             menuItem -l "Connect Field" -c ("connectDynamic -f " + $object);
  1101.             menuItem -l "Connect Emitter" -c ("connectDynamic -em " + $object);
  1102.             menuItem -l "Connect Collision" -c ("connectDynamic -c " + $object);
  1103.         }
  1104.         
  1105.         setParent -m $parent;
  1106.  
  1107.     } else {
  1108.         warning("Menu " + $parent + " doesn't exist.");
  1109.     }
  1110. }
  1111.